<template>
	<view class="Main">
		<!-- 		<view class="SearchDiv">
			<view class="TopDiv">
				<uni-search-bar @confirm="search" v-model="searchValue" @input="input" placeholder="一键查商品"
					@clear="clear" cancelButton="none" style="width: 100%;">
				</uni-search-bar>
				<button class="JoinButton" style="margin-top: 0;width: 30vw;height: 71rpx;font-size: 26rpx;" type="primary"
					@tap="PiLiangSetCode(item)">
					{{PiLiang==true?'完成':'批量操作'}}
				</button>
			</view>
		</view> -->


		<view class="content1">
			<view class="Lists">
				<view :class="PiLiang == true ?'List ChangeListHeight':'List'" v-for="item in ShanPinList"
					:key="item.id">
					<view class="ItemTopDiv">
						<checkbox :value="item.id" color="red" class="CheckBoxClass" v-if="PiLiang"
							:checked="item.checked" />

						<view :class="PiLiang == true ?'PiLiangImg':'ListLeft'">
							<image src="/static/icons/NoPhoto.jpg" mode="" v-if="item.imageUrl==null"></image>
							<image :src="item.imageUrl" mode="" v-else></image>
						</view>

						<view class="ListRight">
							<view class="LeftDiv">
								<view class="ListRigihtTop">
									{{ item.name }}
									<image src="../../../static/icons/Del.svg" mode="" class="DelImage"
										@click="DelItem(item)"></image>
								</view>
								<view class="ListRighDescDiv">

									<view class="ListRigihtShouJian">
										条码：{{ item.barcode }}
									</view>
									<view class="ListRigihtKuCun">
										库存：{{ item.stock }}
									</view>

									<view class="ListRigihtShouJian">
										零售价：
										<view class="ListRightMoney">
											￥{{ item.salePrice }}
										</view>
									</view>
								</view>
							</view>

							<!-- 							<view class="listRightBottom">
								￥{{ item.salePrice }}
							</view> -->
						</view>
					</view>
					<view class="Xian"></view>
					<view class="ItemBottomDiv" :style="IsRuKu?'justify-content: space-between':''">
						<view class="ListRigihtKuCun" v-if="IsRuKu" style="margin-left: 30rpx">
							入货价：{{ item.JinHuoJia }}
						</view>
						<view class="ListRigihtKuCun" v-if="type =='specialActivity' || type =='vip_activity'"
							style="margin-left: 30rpx">
							活动价格：{{ item.JinHuoJia }}
						</view>
						<view class="ListRigihtKuCun" v-if="IsRuKu">
							入货库存：{{ item.RuKuNum }}
						</view>
						<view class="ListRigihtKuCun" v-if="type =='specialActivity' || type =='vip_activity'">
							折扣：{{ item.LinSouJia }}
						</view>

						<button class="JoinButton" type="primary" @tap="SetCode(item)"
							v-if="type =='specialActivity' || type =='RuKu' || type =='vip_activity'">
							{{ IsRuKu?'修改入库':'设置折扣'}}
						</button>
					</view>
				</view>
			</view>
		</view>

		<uni-popup ref="popupRuKu" background-color="#fff">
			<view class="PopTop">
				<view class="PopTitle">
					采购数量
				</view>
				<view class="PopClose">
					<image src="../../../static/icons/Close.svg" mode="" class="CloseImg"></image>
				</view>
			</view>
			<view class="PopIndex">
				<view class="PopItemDiv">
					<view class="PopItemTitle">
						入库数量
					</view>
					<uni-easyinput v-model="CaiGou.RuKuNum" type="number" :clearable="false"></uni-easyinput>
					<view class="PopItemDanWei">
						个
					</view>
				</view>
				<view class="PopXian"></view>
				<view class="PopItemDiv">
					<view class="PopItemTitle">
						进货价
					</view>
					<uni-easyinput v-model="CaiGou.JinHuoJia" type="digit" :clearable="false"></uni-easyinput>
					<view class="PopItemDanWei">
						元
					</view>
				</view>
				<view class="PopXian"></view>
				<view class="PopItemDiv">
					<view class="PopItemTitle">
						零售价
					</view>
					<uni-easyinput v-model="CaiGou.LinSouJia" type="digit" :clearable="false"></uni-easyinput>
					<view class="PopItemDanWei">
						元
					</view>
				</view>
				<view class="PopXian"></view>
				<view class="PopItemDiv">
					<view class="PopItemTitle">
						小计：
					</view>
					<view class="PopItemDanWei" style="color: black;">
						{{Number(CaiGou.JinHuoJia)*Number(CaiGou.RuKuNum)}}元
					</view>
				</view>
			</view>
			<view class="PopCancel">
				<button class="ButtonCancel" @click="Cancel">取消</button>
				<button class="ButtonQueDing" @click="QueDing">确定</button>
			</view>
		</uni-popup>


		<view class="OutLogin1" v-if="PiLiang">
			<view class="ButtonGroup">
				<checkbox-group @change="ChangeQuanXuan" class="CheckboxGroup">
					<checkbox color="red" class="CheckBoxClass" value="quanxuan" />全选
				</checkbox-group>
				<button class="PiLiangButton" type="primary" @tap="SetCode(item)">
					去分
				</button>
				<button class="PiLiangButton Fen" type="primary" @tap="SetCode(item)">
					去角分
				</button>
				<button class="PiLiangZheKouButton" type="primary" @tap="WanCheng">
					完成
				</button>
			</view>
		</view>

		<uni-popup ref="popup7" background-color="#fff" @change="change">
			<view class="PopTop">
				<view class="PopTitle">
					{{ PiLiang == true? '批量折扣':'商品折扣'}}
				</view>
				<view class="PopClose">
					<image src="../../../static/icons/Close.svg" mode="" class="CloseImg"></image>
				</view>
			</view>
			<view class="PopIndex">
				<view class="PopItemDiv">
					<view class="PopItemTitle">
						活动价格（元）
					</view>
					<uni-easyinput v-model="CaiGou.JinHuoJia" type="digit" :clearable="false"
						@input="ActiveInput"></uni-easyinput>
					<view class="PopItemDanWei">
						元
					</view>
				</view>
				<view class="PopXian"></view>
				<view class="PopItemDiv">
					<view class="PopItemTitle">
						折扣（折）
					</view>
					<uni-easyinput v-model="CaiGou.LinSouJia" type="digit" :clearable="false"
						@input="ActiveInput2"></uni-easyinput>
					<view class="PopItemDanWei">
						折
					</view>
				</view>
				<!-- <view class="PopXian"></view> -->
				<!-- 				<view class="PopItemDiv">
					<view class="PopItemTitle">
						减价数
					</view>
					<uni-easyinput v-model="ZheKouShu" type="digit" :clearable="false"></uni-easyinput>
					<view class="PopItemDanWei">
						元
					</view>
				</view> -->

				<view class="PopXian"></view>


				<view class="PopItemDiv">
					<view class="PopItemTitle">
						零售价：
					</view>
					<view class="PopItemDanWei" style="color: black;">
						{{CaiGou.salePrice}}元
					</view>
				</view>

				<!-- 				<view class="PopTip">
					折扣与减价促销方式只能使用其中一种，直接改促销价默认为减价促销方式 <text class="More">了解更多</text>
				</view>
				<radio-group @change="radioChange" class="RadioGroup1">
					<label class="radio">
						<radio value="r1" checked="true" color="black" />保留角分
					</label>
					<label class="radio">
						<radio value="r2" color="black" />去角分
					</label>
					<label class="radio">
						<radio value="r3" color="black" />去分
					</label>
				</radio-group>
				<view class="PopTip">
					去角分会自动切换为减价模式，区间价宝贝去角分不生效
				</view> -->



			</view>



			<view class="PopCancel" @click="PopCancel">
				<button class="ButtonCancel">取消</button>
				<button class="ButtonQueDing">确定</button>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		props: {
			type: {
				type: String,
				default: ""
			}
		},
		data() {
			return {
				CaiGou: {},
				IsRuKu: false,
				colorIndex: 0,
				activeColor: 'rgba(54, 152, 252, 1)',
				current: 0,
				styleType: 'text',
				items: ['商品库', '已选宝贝'],
				searchValue: '',
				ShanPinList: [],

				YiXuanList: [],
				range: [],
				storeId: '',
				value: '', // 类别
				PiLiang: false, // 批量操作
				Searchquery: {
					"pageNum": 1,
					"pageSize": 10,
				},
			}
		},
		mounted() {
			// this.queryGoodsByBarcode("test2(该字段不能重复)")
			this.storeId = wx.getStorageSync("SelectMenDian")
			this.range = []

			uni.$on("SetYiXuanList", (data) => {
				this.IsRuKu = true
				if (this.ShanPinList.length == 0) {
					this.ShanPinList = JSON.parse(JSON.stringify(data))
				} else {
					JSON.parse(JSON.stringify(data)).forEach(item => {
						this.ShanPinList.unshift(item)
					})
				}
			})
			console.log(111, this.type);
			uni.$on("SetYiXuanList2", (data) => {
				this.IsRuKu = false
				if (this.ShanPinList.length == 0) {
					this.ShanPinList = JSON.parse(JSON.stringify(data))
				} else {
					JSON.parse(JSON.stringify(data)).forEach(item => {
						this.ShanPinList.unshift(item)
					})
				}
			})
			uni.$on("SetDuiHuanList", (data) => {
				this.IsRuKu = false

				this.ShanPinList = JSON.parse(JSON.stringify(data))

			})
			// if (uni.getStorageSync("ShanPinList")) {
			// 	this.ShanPinList = JSON.parse(uni.getStorageSync("ShanPinList"))
			// }
		},

		onLoad(option) {

			// this.storeId = wx.getStorageSync("SelectMenDian")
			// this.range = []
			// this.goodsTypeQuery()
			// this.platformGoodsQuery(1)
		},
		inject: ["CancelPiLiangButton"],
		methods: {
			PopCancel() {
				this.$refs.popup7.close()
			},
			ActiveInput() {
				if (!this.IsRuKu)
					this.CaiGou.LinSouJia = Number(this.CaiGou.JinHuoJia / this.CaiGou.salePrice * 10).toFixed(2)
			},
			ActiveInput2() {
				if (!this.IsRuKu)
					this.CaiGou.JinHuoJia = this.CaiGou.LinSouJia / 10 * this.CaiGou.salePrice
			},
			QueDing() {
				this.$refs.popupRuKu.close()
			},
			DelItem(item) {
				this.ShanPinList.forEach((item1, index) => {
					if (item.id == item1.id) {
						this.ShanPinList.splice(index, 1);
					}
				})

			},
			getShanPinList() {

				return this.ShanPinList;
			},
			setShanPinList(data) {
				this.ShanPinList = data;
			},
			WanCheng() {
				this.PiLiang = false
				this.CancelPiLiangButton()
			},
			ChangeQuanXuan(e) {
				if (e.detail.value.length == 0) {
					this.ShanPinList.forEach(i => {
						i.checked = false
					});
				} else {
					this.ShanPinList.forEach(i => {
						i.checked = true
					});
				}
			},
			radioChange() {

			},
			SetCode(item) {
				if (this.IsRuKu) {
					this.$refs.popupRuKu.open('bottom')
					this.CaiGou = item
				} else {
					this.$refs.popup7.open('bottom')
					this.CaiGou = item
				}
			},
			PiLiangSetCode() {
				this.PiLiang = true
			},

			NextBuZhou() {
				// uni.navigateBack({
				// 	url: "/pages/promotion/Index",
				// })

				let pages = getCurrentPages(); // 当前页面
				let beforePage = pages[1]; // 上一页

				console.log(beforePage)
				console.log(pages)
				// uni.navigateBack({
				//     delta: 1
				// });
				uni.navigateBack({
					delta: 3,
					success: function() {
						beforePage.onLoad(); // 执行上一页的onLoad方法
					}
				});
			},
			input(res) {
				console.log(res)
				let _this = this

				this.Searchquery.name = res.value
			},
			change(e) {
				console.log("e:", e);

			},
			goodsTypeQuery() { // 类别
				this.$request(this.$api.goodsTypeQuery, null, "POST", false).then(res => {
					if (res.code == '0') {
						let b = {
							"value": '',
							"text": '所有'
						}
						this.range.push(b)
						res.data.forEach(i => {
							let a = {
								"value": i.id,
								"text": i.name
							}
							this.range.push(a)
						})

					} else {
						uni.showToast({
							title: "错误",
							icon: 'error'
						});
					}
				})
			},
			onClickItem(e) { // 切换
				if (this.current != e.currentIndex) {
					this.current = e.currentIndex;
				}
			},

			clear() {
				this.Searchquery.name = ''
				// this.platformGoodsQuery(1)
			},
		}
	}
</script>

<style scoped lang="scss">
	.uni-easyinput__content-input {
		text-align: right;
	}

	.LeftDiv {
		width: 100%;
	}

	.DelImage {
		width: 34rpx;
		height: 34rpx;
		margin-right: 29rpx;
	}

	.ListRigihtShouJian {
		display: flex;
		margin-top: 10rpx;
		font-size: 26rpx;
	}

	.ListRightMoney {
		color: red;
	}

	.segmented-control__text {
		font-size: 0.9rem !important;
		padding: 18rpx 40rpx !important;
	}

	.segmented-control {
		height: 80rpx !important;
	}

	.ButtonGroup {
		display: flex;
		align-items: center;
		gap: 5vw;
		height: 100rpx;
		margin-bottom: -10rpx;
	}

	.CheckboxGroup {
		color: #007afc;
		display: flex;
		align-items: center;
		gap: 20rpx;
		font-size: 30rpx;
	}

	.ChangeListHeight {
		height: 279rpx !important;
	}

	.PiLiangImg image {
		width: 156rpx;
		height: 156rpx;
		margin-left: 39rpx;
		margin-right: 24rpx;
	}

	.CheckBoxClass {
		margin-left: 33rpx;
		margin-right: -10rpx;
	}

	.More {
		color: #61a0d6;
		margin-left: 20rpx;
	}

	.ButtonQueDing {
		width: 44vw;
		height: 80rpx;
		font-size: 30rpx;
		border-radius: 30vw;
		background: #d82425;
		color: white;
		margin-left: 10rpx;
	}

	.ButtonCancel {
		width: 44vw;
		height: 80rpx;
		font-size: 30rpx;
		border-radius: 8vw;
		background: white;
		color: black;
		border: 2rpx solid #dedede;
		margin-right: 10rpx;
	}

	.RadioGroup1 {
		width: 95%;
		font-size: 28rpx;
		display: flex;
		align-items: center;
		gap: 14vw;
	}

	.radio {
		/* margin-right: 10vw; */
	}

	.PopXian {
		border-bottom: 3rpx solid #eaeaea;
		height: 2rpx;
		width: 91%;
	}

	.PopTip {
		color: #9b9b9b;
		font-size: 22rpx;
		margin-top: 29rpx;
		margin-bottom: 52rpx;
		width: 90%;
		line-height: 36rpx;
	}

	.PopIndex {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.PopItemTitle {
		display: flex;
		align-items: center;
		font-weight: 600;
	}

	.uni-combox__input-plac {
		font-size: 24rpx !important;
	}

	.is-input-border {
		border: 0 !important;
		background: none !important;
	}

	.PopItemDanWei {
		color: #9b9b9b;
	}

	.PopItemDiv {
		display: flex;
		align-items: center;

		text-indent: 24rpx;
		color: black;
		font-size: 0.9rem;
		text-align: left;
		background-color: white;
		width: 95%;
		height: 82rpx;
		margin-right: 4vw;
	}

	.PopTop {
		display: flex;
		align-items: center;
		height: 108rpx;
	}

	.PopClose {
		width: 37rpx;
		height: 37rpx;
	}

	.PopTitle {
		margin-left: 20rpx;
		font-size: 30rpx;
		font-weight: 600;
	}

	.uni-searchbar {
		width: 68vw;
	}

	.uni-popup__wrapper {
		background: none !important;
	}

	.CloseImg {
		width: 37rpx;
		height: 36rpx;
		position: absolute;
		right: 24rpx;
		margin-bottom: 18rpx;
	}

	.PopItem {
		height: 100rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		width: 100%;
		border-bottom: 4rpx solid #f0f0f0;
		font-size: 31rpx;
	}

	.PopCancel {
		height: 116rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		width: 100%;
		border-top: 5rpx solid #f0f0f0;
		font-size: 31rpx;
	}

	.uni-searchbar__box {
		border-radius: 5vw !important;
	}

	.OutLoginButton {
		width: 90%;
		height: 76rpx;
		display: flex;
		align-items: center;
		justify-content: center;

		color: rgba(255, 255, 255, 1) !important;
		background-color: #007afc !important;
		border-radius: 6rpx !important;
		font-size: 0.9rem;
		line-height: 150%;
		text-align: center;

	}


	.OutLogin1 {
		width: 100%;
		background: white;
		padding-bottom: 38rpx;
		position: fixed;
		bottom: 0;
		display: flex;
		justify-content: center;
		align-items: center;
		align-content: center;
		padding-top: 18rpx;
	}

	.Main {
		min-height: 100vh;
		background: #f3f3f5;
	}

	.ListRigihtKuCun {
		margin-top: 13rpx;
	}

	.List {
		height: 293rpx;
		background: white;
		padding-top: 23rpx;
		margin-bottom: 13rpx;
	}

	.ListRight {
		height: 158rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 100%;
	}

	.ListRigihtTop {
		font-size: 32rpx;
		font-weight: 600;
		display: flex;
		align-items: center;
		justify-content: space-between;
		width: 100%;
	}

	.listRightBottom {
		font-size: 36rpx;
		font-weight: 600;
		/* margin-top: 18rpx; */
		color: rgba(255, 87, 51, 1);
		margin-right: 68rpx;
	}

	.Xian {
		border-bottom: 2rpx solid #e8e8e8;
		width: 96vw;
		display: flex;
		height: 2rpx;
		margin-left: 2vw;
		justify-content: center;
	}

	/* 	.content {
		margin-top: 8vh;
		padding-bottom: 8vh;
	} */

	.ItemBottomDiv {
		width: 100vw;
		display: flex;
		align-items: center;
		justify-content: space-between;
	}

	.ItemTopDiv {
		display: flex;
		align-items: center;
		padding-bottom: 15rpx;
	}

	.Fen {
		width: 147rpx !important;
	}

	.PiLiangButton {
		width: 130rpx;
		border-radius: 5vw;
		border: 2rpx solid #007afc;
		color: #007afc !important;
		height: 67rpx;
		font-size: 26rpx;
		margin: 0;
		padding: 0;

		background: none !important;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.PiLiangZheKouButton {
		background: #007afc !important;
		color: white;
		width: 180rpx;
		border-radius: 5vw;
		height: 67rpx;
		font-size: 26rpx;
		margin: 0;
		padding: 0;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.JoinButton {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 172rpx;
		border-radius: 5vw;
		/* border: 2rpx solid #b0585a; */
		border: 2rpx solid #007afc !important;
		/* color: #b0585a !important; */
		color: #007afc !important;
		border-radius: 16vw;
		height: 62rpx;
		font-size: 24rpx;
		margin: 0;
		padding: 0;
		margin-right: 29rpx;
		margin-top: 20rpx;
		background: none !important;
	}


	.ListLeft image {
		width: 171rpx;
		height: 171rpx;
		margin-left: 39rpx;
		margin-right: 24rpx;

		color: rgba(255, 195, 0, 1);
		font-size: 36rpx;
		line-height: 150%;
		text-align: left;
		font-weight: bold;
	}

	.TopDiv {
		display: flex;
		align-items: center;
	}

	.uni-select {
		border: 0 !important;
	}

	/* 	.SearchDiv {
		display: flex;
		flex-direction: column;
		justify-content: center;
		position: fixed;
		top: 0;
		width: 100%;
		background: white;
		z-index: 6;
		height: 7vh;
		padding-top: 20rpx;
	} */

	/* 	.uni-searchbar {
		width: auto !important;
	} */
	.uni-select {
		border: 0 !important;
		padding: 0 10rpx !important;
	}

	.uni-searchbar__box {

		display: flex !important;
		justify-content: flex-start !important;
	}

	.segmented-control {
		width: 100vw;
	}
</style>